package gitlab_hook

import "atomgit.com/openlinksaas-org/proto-gen-go.git/events/events_gitlab"

type PipelineHook struct {
	ObjectKind       string                   `json:"object_kind"`
	User             User                     `json:"user"`
	Project          Project                  `json:"project"`
	Commit           Commit                   `json:"commit"`
	ObjectAttributes PipelineObjectAttributes `json:"object_attributes"`
	MergeRequest     MergeRequest             `json:"merge_request"`
	Builds           []Build                  `json:"builds"`
}

func (item *PipelineHook) ToProtoBuf() *events_gitlab.PipelineEvent {
	ret := &events_gitlab.PipelineEvent{
		ObjectKind:       item.ObjectKind,
		User:             item.User.ToProtoBuf(),
		Project:          item.Project.ToProtoBuf(),
		Commit:           item.Commit.ToProtoBuf(),
		ObjectAttributes: item.ObjectAttributes.ToProtoBuf(),
		MergeRequest:     item.MergeRequest.ToProtoBuf(),
		Builds:           []*events_gitlab.Build{},
	}
	if item.Builds != nil {
		for _, build := range item.Builds {
			ret.Builds = append(ret.Builds, build.ToProtoBuf())
		}
	}
	return ret
}
